package com.tsj.spzx.controller;

import com.tsj.spzx.model.vo.common.Result;
import com.tsj.spzx.model.vo.common.ResultCodeEnum;
import com.tsj.spzx.service.FileUpService;
import org.junit.jupiter.api.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin(allowedHeaders = "*", allowCredentials = "true", originPatterns = "*")
@RequestMapping("/admin/system")
@Tag("文件上传")
public class FileUpController {

    @Autowired
    private FileUpService fileUpService;

    /**
     * 文件上传到minio 返回url链接
     * @param file
     * @return
     */
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) {
        String url = fileUpService.fileUpload(file);
        return Result.build(url, ResultCodeEnum.SUCCESS);
    }
}
